import { createStore, applyMiddleware, combineReducers } from 'redux';

import thunk from 'redux-thunk';

export const counterReducer = (state = 0, { type, payload }) => {
  switch (type) {
    case 'ADD':
      return state + payload;
    case 'MINUS':
      return state - payload;
    default:
      return state;
  }
};

export const userReducer = (state = [], { type, payload }) => {
  switch (type) {
    case 'ADD_USER':
      state.push({ name: '123' });
      return state;
    default:
      return state;
  }
};

const store = createStore(
  combineReducers({
    count: counterReducer,
    user: userReducer,
  }),
  applyMiddleware(thunk)
);

export default store;
